//
//  Date+Extension.swift
//  Weibo
//
//  Created by 张俭 on 16/8/19.
//  Copyright © 2016年 张俭. All rights reserved.
//

import Foundation
extension Date {
    
    var day : String {
        let cmp = Calendar.current.component(.day, from: self)
        return cmp == 0 ? "" : "\(cmp)"
    }
    
    var month : String {
        let cmp = Calendar.current.component(.month, from: self)
        return cmp == 0 ? "" : "\(cmp)"
    }
    
    var year : String {
        let cmp = Calendar.current.component(.year, from: self)
        return cmp == 0 ? "" : "\(cmp)"
    }
    
    var weekday : String {
        let cmp = Calendar.current.component(.weekday, from: self)
        switch cmp {
        case 1:
            return "星期天"
        case 2:
            return "星期一"
        case 3:
            return "星期二"
        case 4:
            return "星期三"
        case 5:
            return "星期四"
        case 6:
            return "星期五"
        case 7:
            return "星期六"
        default:
            return ""
        }
    }
    
    func string(withFormat format:String) -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = format
        return dateFormatter.string(from: self)
    }
}
